package com.fupeng.thoughtworks;

/**
 * Created by lecky on 2016/9/21 0021.
 *
 */
public class Animal implements Comparable{
    private String animal_id;
    private int x_pos;
    private int y_pos;
    private int x_move;
    private int y_move;

    public Animal() {
    }

    public Animal(String animalStr) {
        String[] str = animalStr.split(" ");
        animal_id=str[0];
        x_pos=Integer.parseInt(str[1]);
        y_pos=Integer.parseInt(str[2]);
        if(str.length==5){
            x_move=Integer.parseInt(str[3]);
            y_move=Integer.parseInt(str[4]);
        }
    }

    /**
     * 检测当前this对象的x_pos，y_pos是否有效
     * @param animal
     * @return
     */
    public boolean checkData(Animal animal){
        if(this.x_pos==animal.x_pos && this.y_pos==animal.y_pos)
            return true;
        else
            return false;
    }

    public String getAnimal_id() {
        return animal_id;
    }

    public void setAnimal_id(String animal_id) {
        this.animal_id = animal_id;
    }

    public int getX_pos() {
        return x_pos;
    }

    public void setX_pos(int x_pos) {
        this.x_pos = x_pos;
    }

    public int getY_pos() {
        return y_pos;
    }

    public void setY_pos(int y_pos) {
        this.y_pos = y_pos;
    }

    public int getX_move() {
        return x_move;
    }

    public void setX_move(int x_move) {
        this.x_move = x_move;
    }

    public int getY_move() {
        return y_move;
    }

    public void setY_move(int y_move) {
        this.y_move = y_move;
    }

    @Override
    public int compareTo(Object o) {
        Animal animal = (Animal) o;
        if(this.animal_id.compareTo(animal.getAnimal_id())<0)
            return -1;
        else if(this.animal_id.compareTo(animal.getAnimal_id())>0)
            return 1;
        else
            return 0;
    }
}
